package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2023/2/23 18:55
 * @description 977. 有序数组的平方
 */
public class Test977 {

    public static void main(String[] args) {

    }


    public int[] sortedSquares(int[] nums) {
        int[] resp = new int[nums.length];
        int key = nums.length - 1;
        for (int i = 0, j = nums.length - 1; i <= j; ) {
            int i2 = nums[i] * nums[i];
            int j2 = nums[j] * nums[j];
            if (i2 > j2) {
                resp[key--] = i2;
                i++;
            } else {
                resp[key--] = j2;
                j--;
            }

        }
        return resp;
    }
}
